package com.distortiongames.escalol.components.render
{
	import com.pblabs.core.PBComponent;
	import com.pblabs.time.IAnimated;
	import com.pblabs.time.ITicked;
	import com.pblabs.time.TimeManager;
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.Event;
	
	/**
	 * ...
	 * @author Jefferson Wagner
	 */
	public class Renderer extends PBComponent implements IAnimated, ITicked
	{
		[Inject]
		public var stage:Stage;
		
		[Inject]
		public var timeManager:TimeManager;
		
		private var _sprite:Sprite;
		private var _dirty:Boolean;
		
		public function get sprite():Sprite
		{
			return _sprite;
		}
		
		public function get dirty():Boolean 
		{
			return _dirty;
		}
		
		public function set dirty(value:Boolean):void 
		{
			_dirty = value;
		}
		
		override protected function onAdd():void
		{
			super.onAdd();
			_sprite = new Sprite();
			
			stage.addChild(_sprite);
			timeManager.addAnimatedObject(this);
			timeManager.addTickedObject(this, 9);
		}
		
		public function onTick() : void {
			applyBindings();
		}
		
		public function onFrame() : void
		{
			if (_dirty) {
				doRender();
				_dirty = false;
			}
		}
		
		public function doRender():void
		{

		}
		
		override protected function onRemove():void
		{
			super.onRemove();
			stage.removeChild(_sprite);
		}
	}

}